
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  
  <title>node使用记录 | cymiao</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="node使用小知识 在使用npm运行两个监听端口的时候比如我需要运行mockserver 以及 项目,如下:  1234567&quot;scripts&quot;: &amp;#123;  &quot;dev&quot;: &quot;webpack-dev-server --inline --progress --config build/webpack.dev.conf.js&quot;,  &quot;start&quot;: &quot;npm run dev&quot;,  &quot;build&quot;:">
<meta name="keywords" content="node,npm">
<meta property="og:type" content="article">
<meta property="og:title" content="node使用记录">
<meta property="og:url" content="https://cyshigehaohaizi.gitee.io/2018/08/07/node/node使用记录/index.html">
<meta property="og:site_name" content="cymiao">
<meta property="og:description" content="node使用小知识 在使用npm运行两个监听端口的时候比如我需要运行mockserver 以及 项目,如下:  1234567&quot;scripts&quot;: &amp;#123;  &quot;dev&quot;: &quot;webpack-dev-server --inline --progress --config build/webpack.dev.conf.js&quot;,  &quot;start&quot;: &quot;npm run dev&quot;,  &quot;build&quot;:">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2018-08-07T07:51:12.656Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="node使用记录">
<meta name="twitter:description" content="node使用小知识 在使用npm运行两个监听端口的时候比如我需要运行mockserver 以及 项目,如下:  1234567&quot;scripts&quot;: &amp;#123;  &quot;dev&quot;: &quot;webpack-dev-server --inline --progress --config build/webpack.dev.conf.js&quot;,  &quot;start&quot;: &quot;npm run dev&quot;,  &quot;build&quot;:">
  
    <link rel="alternative" href="/atom.xml" title="cymiao" type="application/atom+xml">
  
  
  <link rel="stylesheet" href="/cy_home/css/style.css">
  
    <!--<link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">-->
  
  <!--[if lt IE 9]><script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7/html5shiv.min.js"></script><![endif]-->
  
  

</head>

<body>
<div id="container">
  <div id="wrap">
    <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <nav id="upper-nav" class="inner">
      <a id="main-nav-toggle" class="nav-icon"></a>
      <div class="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        
          <a id="nav-github" class="nav-icon" href="https://github.com/myname"></a>
        
      </div>
    </nav>
    <div id="header-title">
      
        <h1 id="blog-title-wrap">
          <a href="/" id="blog-title">My Blog</a>
        </h1>
      
    </div>
    <div id="contenedor">
      <ul class="cube">
        <li class="cara">cy</li>
        <li class="cara">A</li>
        <li class="cara">B</li>
        <li class="cara">C</li>
        <li class="cara">D</li>
        <li class="cara">E</li>
      </ul>
    </div>
    <nav id="main-nav">
      
        <a class="main-nav-link" href="/cy_home/">Home</a>
      
        <a class="main-nav-link" href="/cy_home/archives">Archives</a>
      
        <a class="main-nav-link" href="/cy_home/about">About</a>
      
      <a class="main-nav-link st-search-show-outputs">搜索</a>
    </nav>
  </div>
</header>

    <div class="outer">
      <section id="main"><article id="post-node/node使用记录" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <h3 href="/cy_home/2018/08/07/node/node使用记录/" class="article-date">
  <time datetime="2018-08-07T06:44:00.000Z" itemprop="datePublished">2018-08-07</time>
</h3>
    
  </div>
  <div class="article-inner">
  <div class="curve-down">
  <div class="fill-content">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      node使用记录
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        
        <h3 id="node使用小知识"><a href="#node使用小知识" class="headerlink" title="node使用小知识"></a>node使用小知识</h3><ol>
<li>在使用npm运行两个监听端口的时候比如我需要运行mockserver 以及 项目,如下:</li>
</ol>
<figure class="highlight xquery"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">"scripts"</span>: &#123;</span><br><span class="line">  <span class="string">"dev"</span>: <span class="string">"webpack-dev-server --inline --progress --config build/webpack.dev.conf.js"</span>,</span><br><span class="line">  <span class="string">"start"</span>: <span class="string">"npm run dev"</span>,</span><br><span class="line">  <span class="string">"build"</span>: <span class="string">"node build/build.js"</span>,</span><br><span class="line">  <span class="string">"mock"</span>:<span class="string">"node net.js http://192.168.17.18:10000/mock/5b68f9b10b81e375f173f0ed http://localhost:8081"</span>,</span><br><span class="line">  <span class="string">"qts"</span>:<span class="string">"npm run start &amp;&amp; npm run mock "</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>我需要同时运行start和mock 使用第三种方式始终只会运行第一个,这里需要安装一个npm 插件<code>concurrently</code>,我这里安装在全局</p>
<figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm <span class="keyword">install</span> -g concurrently</span><br></pre></td></tr></table></figure>
<p>这里再查看下<code>concurrently</code>语法:</p>
<p>控制台直接使用:</p>
<figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">concurrently</span> <span class="string">"command1 arg"</span> <span class="string">"command2 arg"</span></span><br></pre></td></tr></table></figure>
<p>在package.json中也可以配置:</p>
<figure class="highlight 1c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="string">"start"</span>: <span class="string">"concurrently \"</span>command1 arg\<span class="string">" \"</span>command2 arg\<span class="string">""</span></span><br></pre></td></tr></table></figure>
<p>那么我们这里需要吧qts命令改下:</p>
<figure class="highlight autoit"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">"qts"</span>: <span class="string">"concurrently \"</span>npm <span class="built_in">run</span> start\<span class="string">" \"</span>npm <span class="built_in">run</span> mock\<span class="string">""</span></span><br></pre></td></tr></table></figure>
<p>好了现在我们执行<code>npm run qts</code>两句都执行成功</p>

      
    </div>
    <footer class="article-footer">
      <div class="article-footer-content">
        
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/cy_home/tags/node/">node</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/cy_home/tags/npm/">npm</a></li></ul>

        <a data-url="https://cyshigehaohaizi.gitee.io/2018/08/07/node/node使用记录/" data-id="cjnr90az10001ok76smh6i98l" class="article-share-link">分享到</a>
        
      </div>
    </footer>
  </div>
  </div>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/cy_home/2018/10/27/npm/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">下一篇</strong>
      <div class="article-nav-title">
        
          npm
        
      </div>
    </a>
  
  
    <a href="/cy_home/2018/08/02/doclever/doclever_use/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">上一篇</strong>
      <div class="article-nav-title">doclever使用</div>
    </a>
  
</nav>

  
</article>


</section>
      
      <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">近期文章</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/cy_home/2018/10/27/npm/npm组件发布/">npm + webpack + vue 创建发布一个组件</a>
          </li>
        
          <li>
            <a href="/cy_home/2018/10/27/npm/">npm</a>
          </li>
        
          <li>
            <a href="/cy_home/2018/08/07/node/node使用记录/">node使用记录</a>
          </li>
        
          <li>
            <a href="/cy_home/2018/08/02/doclever/doclever_use/">doclever使用</a>
          </li>
        
          <li>
            <a href="/cy_home/2018/07/31/MongoDB/MongoDB/">MongoDB</a>
          </li>
        
      </ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">标签</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/cy_home/tags/DOClever/">DOClever</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/cy_home/tags/MongoDB/">MongoDB</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/cy_home/tags/doclever/">doclever</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/cy_home/tags/mock/">mock</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/cy_home/tags/node/">node</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/cy_home/tags/npm/">npm</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/cy_home/tags/rap/">rap</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/cy_home/tags/taFaceNex/">taFaceNex</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/cy_home/tags/vue/">vue</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/cy_home/tags/vue-cli/">vue-cli</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/cy_home/tags/webpack/">webpack</a><span class="tag-list-count">1</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">归档</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/cy_home/archives/2018/10/">十月 2018</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/cy_home/archives/2018/08/">八月 2018</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/cy_home/archives/2018/07/">七月 2018</a><span class="archive-list-count">5</span></li></ul>
    </div>
  </div>

  
</aside>
      
    </div>
    <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2018 cy<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
      .
      Theme by <a href="https://github.com/sun11/hexo-theme-paperbox" target="_blank">Paperbox</a>
    </div>
  </div>
</footer>
  </div>
  <nav id="mobile-nav">
  
    <a href="/cy_home/" class="mobile-nav-link">Home</a>
  
    <a href="/cy_home/archives" class="mobile-nav-link">Archives</a>
  
    <a href="/cy_home/about" class="mobile-nav-link">About</a>
  
  <a href="#search" class="mobile-nav-link st-search-show-outputs">搜索</a>
</nav>

  

<!-- totop start -->
<div id="totop">
	<a title="返回顶部"></a>
</div>
<!-- totop end -->

<!-- swiftype search start -->

<!-- swiftype search end -->



<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>

<script src="//cdnjs.cloudflare.com/ajax/libs/lrsjng.jquery-qrcode/0.12.0/jquery.qrcode.min.js"></script>


  <link rel="stylesheet" href="/cy_home/fancybox/jquery.fancybox.css">
  <script src="/cy_home/fancybox/jquery.fancybox.pack.js"></script>


<script src="/cy_home/js/script.js"></script>

</div>
</body>
</html>
